<?php
header("Content-type:text/html;charset=utf-8");
session_start();
$db= require 'db.php';

if (empty($_POST)) {
// 	// 表单为空 跳转到登陆界面
	require 'view/login.html';
}else{
	//判断表单里面的用户名和密码都跟数据库里面的匹配
	foreach ($db as $d) {
		
		if ($d['username'] == $_POST['username'] && $d['password'] == $_POST['password']){
	// 	//把$d的值存储到 SESSION里面
		$_SESSION['user'] = $d;
		print_r($_SESSION['user']);exit;
		header('location:index.php');
		
		}
	}
		// echo 'ok';exit;
	echo "帐号或密码错误
			<script>
				setTimeout(function()
					{
						location.href='login.php';
					},2000);
			</script>";
	
}

?>